package org.lw.ssm.controller;


import org.lw.ssm.Entity.User;
import org.lw.ssm.response.ApiResponse;
import org.lw.ssm.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping("/{id}")
    public ResponseEntity<ApiResponse<User>> sayUser(@PathVariable("id") int id){
        System.out.println(userService);

        User user = userService.findUserById(id);
        return  ResponseEntity.ok().body(new ApiResponse<>(200,"返回给前端的数据",user));
    }
    @GetMapping("/all")
    public ResponseEntity<ApiResponse<List<User>>> findAll(){
        System.out.println(userService);

        List<User> allUsers = userService.findAllUsers();
        return  ResponseEntity.ok().body(new ApiResponse<>(200,"返回给前端的数据",allUsers));
    }
    @DeleteMapping("/{id}")
    public ResponseEntity<ApiResponse<User>> delete(@PathVariable("id") int id){

        int i = userService.deleteUser(id);
        return  ResponseEntity.ok().body(new ApiResponse<>(200,"删除成功",null));
    }

}
